/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = test_ora.c                                        */
/*  NOTE      =                                                    */
/*  DATE      = 2016/03/10 by songbb                               */
/*******************************************************************/

#include <stdio.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "apmtest_cunit.h"
#include "frcomm.h"
#include "frmem.h"
#include "../../src/module/activemq/config.h"
#include "../../src/module/activemq/activemq_common.h"
#include "../../src/module/activemq/activemq_base_type.h"
#include "../../src/module/activemq/activemq_core.h"
#include "t_activemq_comm/t_activemq_comm.h"
#include "t_activemq_openwire_parse/t_activemq_openwire_parse.h"

#include <frservice_mng.h>

static Frmemstat_mng g_st_memstat_mng={0,FR_MEMSTAT_COUNT_MAX};
static pthread_rwlock_t  g_memstat_rwlock = PTHREAD_RWLOCK_INITIALIZER;
static Frmem_env g_st_mem_env = {&g_st_memstat_mng, &g_memstat_rwlock};

FR_STATIC Frexp_ref g_st_expRef={NULL, NULL};
FR_STATIC Frexp_ref g_st_exp2Ref={NULL, NULL};
FR_STATIC Frservice_ref g_st_serviceRef={NULL, NULL};
FR_STATIC Frreport_session_ref g_st_report_session_Ref={NULL, NULL, NULL};
FR_STATIC Report_module g_st_report_moduleRef = {NULL, NULL, NULL, NULL, NULL};

ApmContext g_st_apm_context = {&g_st_expRef, &g_st_exp2Ref, &g_st_serviceRef, &g_st_report_session_Ref, &g_st_report_moduleRef, &g_st_mem_env};

void add_suites(FunType *p_func, int i_suites_len, FunType fp)
{
    int i_loop = 0;
    for (;i_loop < i_suites_len; i_loop++)
    {
        if (p_func[i_loop] == NULL)
        {
            p_func[i_loop] = fp;
            break;
        }
    }
}

int main(int argc, char **argv)
{
    if (fr_slab_init(&g_st_mem_env, MODULE_NAME) == NULL)
        return FR_FAIL;

    apmtest_cunit_registry();

    FunType fun_suites[1024];
    memset(fun_suites, 0x00, sizeof(fun_suites));
    int i_suites_len = sizeof(fun_suites) / sizeof(FunType);
    int i_loop = 0;

    //activemq_comm
    add_suites(fun_suites, i_suites_len, add_suite_activeMQ_boolean_stream_get);
    add_suites(fun_suites, i_suites_len, add_suite_activeMQ_boolean_stream_parse1);
    add_suites(fun_suites, i_suites_len, add_suite_activeMQ_boolean_stream_parse2);
    add_suites(fun_suites, i_suites_len, add_suite_activeMQ_get_data);
    add_suites(fun_suites, i_suites_len, add_suite_activeMQ_skip_string);
    add_suites(fun_suites, i_suites_len, add_suite_activeMQ_get_user);
    add_suites(fun_suites, i_suites_len, add_suite_activeMQ_get_pass);
    add_suites(fun_suites, i_suites_len, add_suite_activeMQ_skip_long);
    add_suites(fun_suites, i_suites_len, add_suite_activeMQ_skip_boolean);
    add_suites(fun_suites, i_suites_len, add_suite_activeMQ_skip_bytes);
    add_suites(fun_suites, i_suites_len, add_suite_get_broker_id);
    add_suites(fun_suites, i_suites_len, add_suite_get_connection_id);
    add_suites(fun_suites, i_suites_len, add_suite_skip_connection_id);
    add_suites(fun_suites, i_suites_len, add_suite_get_session_id);
    add_suites(fun_suites, i_suites_len, add_suite_get_consumer_id);
    add_suites(fun_suites, i_suites_len, add_suite_skip_consumer_id);
    add_suites(fun_suites, i_suites_len, add_suite_get_destination);
    add_suites(fun_suites, i_suites_len, add_suite_skip_destination);
    add_suites(fun_suites, i_suites_len, add_suite_get_activemq_destination);
    add_suites(fun_suites, i_suites_len, add_suite_skip_producer_id);
    add_suites(fun_suites, i_suites_len, add_suite_get_local_transaction_id);
    add_suites(fun_suites, i_suites_len, add_suite_skip_transaction_id);
    add_suites(fun_suites, i_suites_len, add_suite_skip_message_id);

    //activemq_oepnwire_parse
    add_suites(fun_suites, i_suites_len, add_suite_openwire_wireinfo_tightUnmarshal);
    add_suites(fun_suites, i_suites_len, add_suite_openwire_brokerinfo_tightUnmarshal);
    add_suites(fun_suites, i_suites_len, add_suite_openwire_connectioninfo_tightUnmarshal);
    add_suites(fun_suites, i_suites_len, add_suite_openwire_sessioninfo_tightUnmarshal);
    add_suites(fun_suites, i_suites_len, add_suite_openwire_consumerinfo_tightUnmarshal);
    add_suites(fun_suites, i_suites_len, add_suite_openwire_producerinfo_tightUnmarshal);
    add_suites(fun_suites, i_suites_len, add_suite_openwire_transactioninfo_tightUnmarshal);
    add_suites(fun_suites, i_suites_len, add_suite_openwire_keepaliveinfo_tightUnmarshal);
    add_suites(fun_suites, i_suites_len, add_suite_openwire_shutdowninfo_tightUnmarshal);
    add_suites(fun_suites, i_suites_len, add_suite_openwire_removeinfo_tightUnmarshal);
    add_suites(fun_suites, i_suites_len, add_suite_openwire_controlcommand_tightUnmarshal);
    add_suites(fun_suites, i_suites_len, add_suite_openwire_connectioncontrol_tightUnmarshal);
    add_suites(fun_suites, i_suites_len, add_suite_openwire_messagedispatch_tightUnmarshal);
    add_suites(fun_suites, i_suites_len, add_suite_openwire_text_message_tightUnmarshal);
    add_suites(fun_suites, i_suites_len, add_suite_openwire_response_tightUnmarshal);



    for (;i_loop < i_suites_len; i_loop++)
    {
        if (fun_suites[i_loop] != NULL && fun_suites[i_loop]() != 0)
        {
            CU_cleanup_registry();
            return CU_get_error();
        }
    }

    apmtest_cunit_unregistry();
    fr_slab_destroy();

    return 0;
}
